<?php
//接任务
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['set']=$this->plugin_setting('basic');
if($_RQ['op']=='main'){
	$taskid=$_RQ['taskid'];
	$mid=$_SESSION['uid'];
	$task=pdo_get('jy_inclock_task_list',array('uniacid'=>$_SESSION['uniacid'],'id'=>$taskid));
	
	$member=pdo_get('core_members',array('uniacid'=>$_SESSION['uniacid'],'id'=>$mid));
	if (empty($task)){
		exi('任务不存在','error');
	}
	$canPick =$this->model()->checkCanPick($task, $mid);
	if ($canPick['status']==-1) {
		$return['canPick']=$canPick;
		exi($return);
	}
	$stoptime =$this->model()->stoptime($task);
	$taskArr = array('uniacid' => $_SESSION['uniacid'], 'taskid' => $task['id'], 'tasktitle' => $task['title'], 'tasktype' => $task['type'], 'mid' => $mid, 'nickname' => $member['nickname'], 'picktime' => date('Y-m-d H:i:s'), 'task_demand' =>$task['demand'], 'taskimage' => $task['image'], 'reward_data' => $task['reward'], 'followreward_data' => $task['followreward'], 'design_data' => $task['design_data'], 'design_bg' => $task['design_bg'], 'stoptime' => $stoptime, 'require_goods' => $task['requiregoods'], 'member_group' => $task['member_group'], 'auto_pick' => $task['auto_pick']);
	if ($task['type'] == 'poster' && 0 < $task['level2']) {
		$taskArr['level1'] = $task['demand'];
		$taskArr['reward_data1'] = $task['reward'];
		$taskArr['level2'] = $task['level2'];
		$taskArr['reward_data2'] = $task['reward2'];

		if (0 < $task['level3']) {
			$taskArr['reward_data'] = $task['reward3'];
		}
		else {
			$taskArr['reward_data'] = $task['reward2'];
		}
	}
	$table = 'jy_inclock_task_record';
	$recordid = $this->model()->taskSave($table, $taskArr, false);
	if (!$recordid) {
		return array('status'=>'-1','num'=>'1','message'=>'任务接取失败了');
	}
	$taskArr['id'] = $recordid;
	$taskArr['stoptime'] = $stoptime;
	$return['recordid']=$recordid;
	exi('任务接取成功！','','/mine/');
}
